﻿using System;
using System.Data;
using System.Collections;
using CE.Database;

/// <summary>
/// Summary description for PromotionGGDB
/// </summary>
namespace CE.CarInsurance
{
    public class PromotionGGDB
    {
        public PromotionGGDB()
        {
        }

        public DataTable GetPromotion(Int64 PromotionId)
        {
            MyDatabase _db = new MyDatabase();

            SortedList _spara = new SortedList();
            _spara.Add("@PromotionId", PromotionId);
            DataTable _dt = _db.GetDataTable("SELECT * FROM tblPromotionGG WHERE PromotionId = @PromotionId ORDER BY CreatedDate DESC", _spara);

            return _dt;
        }

        public DataTable GetPromotionByCustomer(Int64 CustomerId)
        {
            MyDatabase _db = new MyDatabase();

            SortedList _spara = new SortedList();
            _spara.Add("@CustomerId", CustomerId);
            DataTable _dt = _db.GetDataTable("SELECT * FROM tblPromotionGG WHERE CEUserId = @CustomerId AND Status = 1 ORDER BY CreatedDate DESC", _spara);

            return _dt;
        }

        public void UpdateAgent(Int64 PromotionId, Int64 CustomerId)
        {
            MyDatabase _db = new MyDatabase();

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@PromotionId", PromotionId);
            #endregion

            _db.ExecuteNonSqlStatement("UPDATE tblPromotionGG SET Status = 0, ModifiedDate = dbo.fn_getUTCDateTime() WHERE PromotionId = @PromotionId AND Status = 1 ", _sPara);
            //"AND convert(varchar(8),[CreatedDate],112) = (SELECT TOP 1 convert(varchar(8),[CreatedDate],112) from tblPromotionGG WHERE CEUserId = @CustomerId)"
        }
    }
}
